import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import rootReducer from '../reducers/index.js';

const logger = createLogger();
let createStoreWithMiddleware;
if (process.env.NODE_ENV === 'development') {
  createStoreWithMiddleware = applyMiddleware(thunkMiddleware, logger)(createStore);
} else {
  createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);
}

export default function configureStore(initialState) {
  const store = createStoreWithMiddleware(rootReducer, initialState);
  return store;
}

